<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
 	<script src="../app/lib/jquery-1.6.4.js"></script>
  	<link rel="stylesheet" href="../app/lib/qunit.css"type="text/css" media="screen" />
	<script type="text/javascript" src="../app/lib/qunit.js"></script>
	<script src="../app/js/ListView.js"></script>
	<script>
		$(document).ready(function(){
		//Write test code here format:
			module("ListView");	
			test("addListItem", function(){
				//setup
				var fakelist = $('<ul/>');
				fakelist.listview = function(){};
				listview = agr.ListView(fakelist);
				//Add item to list
				listview.addListItem({
					uid : 2,
					test: "test"}
				);
				//get item checking its in the right location and has the right attribute
				equal((listview.dump()[2].test), "test","UID and LABEL match");
			});

			test("append", function(){
				//setup
				var fakelist = $('<ul/>');
				fakelist.listview = function(){};
				listview =agr.ListView(fakelist);
				var func = function(){return "testF"};
				var testObject = {
					uid : 2,
					html: "test",
					action: func,
					href : "href"}
				var testObject2 = {
					uid : 3,
					html: "test",
					action: func,
					disable: true,
					href : "href"
				}
				listview.addListItem(testObject);
				listview.addListItem(testObject2);
				var appendResult = fakelist.find("li");
				expect(6);
				equal(appendResult.length, 2, "Two Items Appended");
				equal(appendResult.find('a').html(), "test", "Correct inner html");
				ok(appendResult.find('a').first().attr("href"),'href on enabled');
				//Check click event hanlder was set
				var out = appendResult.find('a').data('events').click;
				equal(out[0].handler(), "testF","click function set on enabled");
				ok(!appendResult.find('a').last().data('events'),'No events bound on disabled');
				ok(!appendResult.find('a').last().attr("href"),'No href on disabled');
			});
			test("EditModeAppend", function(){
				var fakelist = $('<ul/>');
				fakelist.listview = function(){};
				listview =agr.ListView(fakelist);
				var afunc = function(){return "atest"};
				var efunc = function(){return "etest"};
				var testObject = {
					uid : 2,
					html: "test",
					action: afunc,
					edit: efunc,
					edithref: "href"}
				var testObject2 = {
					uid : 3,
					html: "test2",
					action : afunc,
					disable: true,
				}
				listview.editOn();
				listview.addListItem(testObject);
				listview.addListItem(testObject2);
				var appendResult = fakelist.find("li");
				expect(7);
				equal(appendResult.length, 2,"Correct number of list items");
				//check 2 anchors per in order to verify split view
				equal(appendResult.find('a').length, 4,"Two edit selects, and two delete buttons");
				//not disabled 
				equal(appendResult.find('a').first().attr("href"), "href","edit href properly set for the enabled");
				//Check write event hanlder was set
				var out = appendResult.find('a').first().data('events').click;
				equal(out[0].handler(), efunc(),"Edit function properly set for the enabled");
				//disabled
				ok(!appendResult.last().find('a').first().attr("href"),"Check no edit href for disabled");
				//Delete button is still there and set
				ok(appendResult.last().find('a').last().data('events').click[0].handler,"delete button is available and usable on disabled");
				equal(appendResult.last().find('a').first().html(),"test2","label is set correctly");
			});
			

		});
	</script>
</head>
<body>
	 <h1 id="qunit-header">QUnit example</h1>
	 <h2 id="qunit-banner"></h2>
	 <div id="qunit-testrunner-toolbar"></div>
	 <h2 id="qunit-userAgent"></h2>
	 <ol id="qunit-tests"></ol>
	 <div id="qunit-fixture">test markup, will be hidden</div>	
</body>
</html>
